package com.xjtu.platform.user.assister.consultChange.imply;

import com.xjtu.platform.common.Utils;
import com.xjtu.platform.common.page.QueryAction;
import com.xjtu.platform.user.assister.consultChange.*;
import com.xjtu.platform.user.assister.consultChange.dao.ConsultChangeDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ConsultChangeServiceImpl implements ConsultChangeService {

    @Resource
    private ConsultChangeDao consultChangeDao;

    @Override
    public Map<String, Object> getConsultRecord(ConsultChangeDto consultChangeDto) {
        return Utils.getPage(consultChangeDto,()->consultChangeDao.getConsultRecord(consultChangeDto));
    }

    @Override
    public Map<String, Object> getFreeTime(FreeTimeDto freeTimeDto) {

        List<FreeTimeModel> list = consultChangeDao.getFreeTime(freeTimeDto);
        List<String > timeList = new ArrayList<>();
        timeList.add("1");
        timeList.add("2");
        timeList.add("3");
        timeList.add(("4"));
        for (FreeTimeModel freeTimeModel : list) {
            if(timeList.contains(freeTimeModel.getTime_id())){
                timeList.remove(freeTimeModel.getTime_id());
            }
        }
        List<FreeTimeModel> infoList = new ArrayList<>();
        for (String time : timeList) {
            infoList.add(consultChangeDao.getTimeInfo(time));
        }
        System.out.println(infoList.toString());
        return Utils.getPage(freeTimeDto, new QueryAction<FreeTimeModel>() {
            @Override
            public List<FreeTimeModel> execute() {
                return infoList;
            }
        });
    }

    @Override
    public boolean insertTimeInfo(InsertTimeDto insertTimeDto) {
        try {
            consultChangeDao.insertTimeInfo(insertTimeDto);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
